#include <Rectangle.h>

Rectangle::Rectangle(const float length, const float width)
{
	setLength(length);
	setWidth(width);
}

Rectangle::Rectangle():length_m(0.0),width_m(0.0)
{
}

double Rectangle::getArea() const
{
	return result_adjust(length_m * width_m);
}

double Rectangle::getPerimeter() const
{
	return result_adjust( (length_m + width_m) * 2);
}

bool Rectangle::setLength(const float length)
{
        if (!isValid(length))
            return false;

        length_m = parameter_adjust(length);
        return true;
}

bool Rectangle::setWidth(const float width)
{
        if (!isValid(width))
            return false;

	width_m = parameter_adjust(width);
        return true;
}

bool Rectangle::isValid(const float value) const
{
    return ((value > 0) && (value <= 100.00));
}

float Rectangle::parameter_adjust(const float parameter) const
{
    return (float)((int)(parameter*100))/100;
}

float Rectangle::result_adjust(const float result) const
{
    return (float)((int)(result*100+0.5))/100;
}
